/**
 * 
 */
package data.model.effort;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import data.EffortProvider;
import data.model.AbstractModel;

/**

 * 
 */
public abstract class Effort extends AbstractModel implements EffortProvider,
		PropertyChangeListener {
	private final String text;

	/**
	 * 
	 */
	public Effort(String text) {
		super();
		this.text = text;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see data.EffortProvider#getEffort()
	 */
	@Override
	public int getEffort() {
		return getEffortRequirementsEngineering()
				+ getEffortArchitectureAndDesign()
				+ getEffortImplementationAndIntegration()
				+ getEffortBuildAndTest() + getEffortProjectManagement();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see data.EffortProvider#getText()
	 */
	@Override
	public String getText() {
		return text;
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		System.out.println(this.getClass() + ": " + evt.getSource() + " --- "
				+ evt.getPropertyName());
		firePropertyChange("effort", null, getEffort());
		String propertyName = evt.getPropertyName();
		if ("effortRequirementsEngineering".equals(propertyName)) {
			firePropertyChange(propertyName, null,
					getEffortRequirementsEngineering());
		} else if ("effortArchitectureAndDesign".equals(propertyName)) {
			firePropertyChange(propertyName, null,
					getEffortArchitectureAndDesign());
		} else if ("effortImplementationAndIntegration".equals(propertyName)) {
			firePropertyChange(propertyName, null,
					getEffortImplementationAndIntegration());
		} else if ("effortBuildAndTest".equals(propertyName)) {
			firePropertyChange(propertyName, null, getEffortBuildAndTest());
		} else if ("effortProjectManagement".equals(propertyName)) {
			firePropertyChange(propertyName, null, getEffortProjectManagement());
		}
	}

}
